<?php


namespace app\cms\model\merchant\goods;


use app\cms\community\lib\QueryModel;
use app\cms\model\merchant\merchantModel;
use iflow\Response;
use think\model\relation\HasManyThrough;

class goodsCardModel extends QueryModel
{
    protected $table = 'goods_card_table';

    // 商品关联
    public function hasGoods(): HasManyThrough
    {
        return $this->hasManyThrough(
            merchantModel::class,
            goodsModel::class,
            'goods_id',
            'merchant_id'
        );
    }

    /**
     * 获取购物车列表
     * @param int $uid
     * @return Response
     */
    public function getGoodsCardList(int $uid): Response
    {
        // 获取用户购物车数据
        $query = $this->hasGoods() -> where([
            'goods_card_table.uid' => $uid
        ]);
        return $this->paginateQuery($query);
    }
}